#@head() #@header()
<title>客户列表</title>
#@aside("user")
<script type="text/javascript" src="#(path)/assets/js/jquery.tmpl.min.js"></script>
<style>
	.box-body{padding:5px !important}
</style>
<div class="content-wrapper">
	<section class="content">
	<div class="nav-tabs-custom">
		#@usermenu("jlff")
		
		<div class="tab-content">
		  <div class="tab-pane active" id="tab_1">
			<div class="box-body">
				<!--<label style="float:left;margin-top:8px;margin-left:10px;">交易名称：</label>
                <input id="jyname" type="text" style="width:120px;float:left" class="form-control" placeholder="">
				<label style="float:left;margin-top:8px;margin-left:5px;">时间区间：</label>
				<input id="sjstart" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				<label style="float:left;margin-top:8px;">—</label>
                <input id="sjend" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				<label style="float:left;margin-top:8px;margin-left:5px;">放款时间：</label>
                <input id="fkstart" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				<label style="float:left;margin-top:8px;">—</label>
                <input id="fkend" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				-->
				<label style="float:left;margin-top:8px;margin-left:5px;">领取时间：</label>
                <input id="hkstart" id="starttime" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				<label style="float:left;margin-top:8px;">—</label>
                <input id="hkend" id="endtime" style="width:120px;float:left" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" type="text" class="form-control" placeholder="">
				
				<label style="float:left;margin-top:8px;margin-left:5px;">奖励类型：</label>
				<select id="jllx" style="width:120px;float:left" class="form-control">
					<option value="">全部</option>
					<option value="jxq">加息券</option>
					<option value="xjhb">现金红包</option>
					<option value="tyj">体验金</option>
				</select>
				 <label style="float:left;margin-top:8px;margin-left:5px;">状态：</label>
				<select id="status" style="width:120px;float:left" class="form-control">
					<option value="">全部</option>
					<option value="normal">未使用</option>
					<option value="used">已使用</option>
					<option value="expire">已过期</option> 
				</select>
				<div class="col-xs-1">
				  <button id="seachuser" type="button" class="btn btn-info btn-flat">搜索</button>
				</div>

            </div>

			<div class="box-body">
				<table  id="example1" class="table table-striped">
					<thead>
						<tr>
							<th>名称</th>
							<th>类型</th>
							<th>发放额度</th>
							<th>状态</th>
							<th>发放事由</th>
							<th>领取时间</th>
							<th>过期时间</th>
							<th>使用时间</th>
							<th>使用标的</th> 
							<th>活动链接</th>
						</tr>
					</thead>
					<tbody id="userlist">
						
					</tbody>
				</table>
				<div class="box-footer clearfix">
				  <ul class="pagination pagination-sm no-margin pull-right">
					<li id="userlist1"><a href="#">首页</a></li>
					<li id="userlist2"><a href="#">上一页</a></li>
					<li><a href="#">第<span id="userlist5"></span>页 共<span id="userlist6"></span>页</a></li>
					<li id="userlist3"><a href="#">下一页</a></li>
					<li id="userlist4"><a href="#">尾页</a></li>
				  </ul>
				</div>
			</div>
			</div>
		</div>
	</div>
	</section>
</div>
#@footer()
<script id="userlistall" type="text/x-jquery-tmpl">
	<tr>
		<td>${name}</td>
		<td>${type}</td>
		<td>${amount}</td>
		<td>${status}</td>
		<td>${access}</td>
		<td>${create_time}</td>
		<td>${valid_end_time}</td>
		<td>${apply_time}</td>
		<td>${bid_name}</td>
		<td>
			<button type="button" onclick="window.open('${link}')" class="btn btn-block btn-primary">打开</button>
		</td>	
	</tr>
</script>
<script>
var totalPage = 1;
var pageNumber = 1;
var jllx="";
var starttime="";
var endtime="";
var status="";
 $(document).ready(function(){
	pageNumber = 1;
	$("#userlist").empty();
	userlist(pageNumber,jllx,starttime,endtime,status);
	$("#userlist5").html(pageNumber);
});
$("#userlist1").click(function(){
	$("#userlist").empty();
	pageNumber = 1;
	userlist(pageNumber,jllx,starttime,endtime,status);
	$("#userlist5").html(pageNumber);
});
$("#userlist2").click(function(){
	if(pageNumber==1){
		alert("当前页是首页!");
	}else{
		$("#userlist").empty();
		pageNumber = pageNumber-1;
		userlist(pageNumber,jllx,starttime,endtime,status);
		$("#userlist5").html(pageNumber);
	}
});
$("#userlist3").click(function(){
	if(pageNumber==totalPage){
		alert("当前页是尾页!"); 
	}else{
	$("#userlist").empty();
		pageNumber = pageNumber +1;
		userlist(pageNumber,jllx,starttime,endtime,status);
		$("#userlist5").html(pageNumber);
	}
});
$("#userlist4").click(function(){
	$("#userlist").empty();
	pageNumber = totalPage;
	userlist(pageNumber,jllx,starttime,endtime,status);
	$("#userlist5").html(pageNumber);
});
$("#seachuser").click(function(){
	$("#userlist").empty();
	jllx = $("#jllx").val();
	pageNumber = 1;
	starttime = $("#starttime").val();
	endtime = $("#endtime").val();
	status = $("#status").val();
	userlist(pageNumber,jllx,starttime,endtime,status);
	$("#userlist5").html(pageNumber);
});

function userlist(pageNumber,jllx,starttime,endtime,status){
	console.log(starttime,endtime); 
	url = "#(path)/couponLog/list?token=#(session.token??)&page="+pageNumber+"&size=15&type="+jllx+"&userId="+id.id+"&createTimeStart="+starttime+"&createTimeEnd="+endtime+"&status="+status;
	$.getJSON(url, function(userli) {
		 console.log(userli);
		totalPage = userli.data.page.totalPage;
		$("#userlist6").html(totalPage);
		$.each(userli.data.page.list, function(i, item){ 
			if(item.type=="tyj"){var type = "体验金";var amount=item.amount+" 元"}
				else if(item.type=="jxq"){var type = "加息券";var amount=item.amount+" %"}
				else if(item.type=="xjhb"){var type = "现金红包";var amount=item.amount+" 元"} 
				else if(item.type=="tzhb"){var type = "投资红包";var amount=item.amount+" 元"}
			if($.isBlank(item.trade)){bid_name=""}else{bid_name=item.trade.bid_name} 
			if(item.access=="direct")
				{var access = "定向红包";}
			else if(item.access=="reg")
				{var access = "注册";}
			else if(item.access=="real")
				{var access = "实名";} 
			else if(item.access=="deposit")
				{var access = "充值";}
			else if(item.access=="trade")
				{var access = "投资";}
			else if(item.access=="birthday")
				{var access = "生日";}
			else if(item.access=="exchange")
				{var access = "积分兑换";}
			if(item.status =="normal"){ 
				var status = "未使用";
			}else if(item.status =="used"){
				var status = "已使用";
			}else if(item.status =="expire"){
				var status = "已过期";
			}
			if($.isBlank(item.coupon)){
				name = "现金红包";
			}else{
				name = item.coupon.name; 
			}
			var userlist = {status:status,valid_end_time:item.valid_end_time,link:item.link,bid_name:bid_name,type:type,access:access,apply_time:item.apply_time,create_time:item.create_time,amount:amount,name:name,summary:item.summary};
			$("#userlistall").tmpl(userlist).appendTo('#userlist');
		});
	});	
}

</script>
</body>
</html>